package com.dareway.reflex;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Class_getField {
    public static void main(String[] args) throws ReflectiveOperationException {
        Class<?> clazz = Class.forName("com.dareway.reflex.Student");
        Object instance = clazz.newInstance();

        Field field = clazz.getField("i");   //获取类的成员字段i
        field.set(instance, 100);   //将类实例instance的成员字段i设置为100

        Field fieldPri = clazz.getDeclaredField("k");   //获取类的成员字段i
        field.setAccessible(true);
        field.set(instance, 100);   //将类实例instance的成员字段i设置为100

        Method method = clazz.getMethod("test");
        method.invoke(instance);
    }
}
